﻿using System;
using CQRS.Events;
using CQRS.Sample.Domain.Commands;

namespace CQRS.Example.SampleApplication.Views
{
    public partial class RegisterRepairForm : BaseForm
    {
        private Guid _planeId;
        private readonly IBus<Command> _commandBus;
        public RegisterRepairForm(IBus<Command> commandBus)
        {
            InitializeComponent();
            _commandBus = commandBus;
        }

        internal void Init(Guid planeId)
        {
            _planeId = planeId;
        }

        private void buttonSavePlaneRepair_Click(object sender, EventArgs e)
        {
            var registerPlaneRepairCommand = new RegisterPlaneRepairCommand
                (_planeId, dateTimePickerRepairDate.Value, textBoxDoneBy.Text,
                textBoxPartRepaired.Text, textBoxChangedPart.Text);
            _commandBus.Publish(registerPlaneRepairCommand);
            _commandBus.Commit();
            Close();
        }
    }
}